package com.yang.guliproduct.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yang.guliproduct.entity.PmsCategoryBrandRelation;
import com.yang.guliproduct.service.impl.PmsCategoryBrandRelationServiceImpl;
import com.yang.guliproduct.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 品牌分类关联 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/guliproduct/pms-category-brand-relation")
public class PmsCategoryBrandRelationController {

    @Autowired
    private PmsCategoryBrandRelationServiceImpl pmsCategoryBrandRelationService;

    @GetMapping("getCategoryBrandRelation/{brandId}")
    public R getCategoryBrandRelation(@PathVariable Long brandId){
        QueryWrapper<PmsCategoryBrandRelation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("brand_id",brandId);
        List<PmsCategoryBrandRelation> list = pmsCategoryBrandRelationService.list(queryWrapper);
        return R.ok().data("list",list);
    }

    @PostMapping("addCategoryBrandRelation")
    public R addCategoryBrandRelation(@RequestBody PmsCategoryBrandRelation pmsCategoryBrandRelation){
        pmsCategoryBrandRelationService.addCategoryBrand(pmsCategoryBrandRelation);
        return R.ok();
    }

    @DeleteMapping("deleteCategoryBrandRelation/{id}")
    public R deleteCategoryBrandRelation(@PathVariable Long id){
        pmsCategoryBrandRelationService.removeById(id);
        return R.ok();
    }

}

